package com.atguigu.queue;

import java.util.LinkedList;
import java.util.Queue;
;
public class MyStack {
    private Queue<Integer> master;
    private Queue<Integer>slave;
    /** Initialize your data structure here. */
    public MyStack() {
        master=new LinkedList<>();
        slave=new LinkedList<>();
    }

    /** Push element x onto stack. */
    public void push(int x) {
        slave.offer(x);
        while(!master.isEmpty()){
            int temp=master.poll();
            slave.offer(temp);
        }
        Queue<Integer>res=slave;
        slave=master;
        master=res;
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        if(master.isEmpty()){
            throw new IllegalArgumentException("Queue is empty!");
        }
        return master.poll();
    }

    /** Get the top element. */
    public int top() {
        if(master.isEmpty()){
            throw new IllegalArgumentException("Queue is empty!");
        }
        return master.peek();
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        return master.isEmpty();
    }
}
